﻿using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Controllers;
using Abp.Runtime.Validation;
using Batman.Cms.Controllers.Inputs;
using Batman.Cms.Services;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Batman.Cms.Controllers
{
    public class ArticleTypeController : AbpController
    {
        public ActionResult Create()
        {
            return View();
        }

        public ArticleTypeAppSvc ArticleTypeAppSvc { get; set; }

        [DisableValidation]
        [HttpPost]
        public ActionResult Create(CreateArticleTypeInput model)
        {
            if (!ModelState.IsValid) return View(model);

            ArticleTypeAppSvc.Create(model);

            return View();
        }

        [HttpGet]
        public ActionResult Index(ArticleTypeFilter filter, PagedResultRequestDto page)
        {
            var result = ArticleTypeAppSvc.GetList(filter);

            return View(result);
        }

        /// <summary>
        /// 获取“文章分类”数据,默认获取全部数据
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Index(ArticleTypeFilter filter)
        {
            var result = ArticleTypeAppSvc.GetList(filter);

            return Json(result);
        }

        public ActionResult Update(int id)
        {
            var model = ArticleTypeAppSvc.Get<UpdateArticleTypeInput>(id);

            return View(model);
        }

        [HttpPost]
        public ActionResult Update(UpdateArticleTypeInput model)
        {
            ArticleTypeAppSvc.Update(model);

            return View(model);
        }
    }
}
